package com.taobao.txc.resourcemanager.mt;

import com.taobao.txc.a.b.g;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.TxcContext;
import com.taobao.txc.common.c.A;
import com.taobao.txc.common.c.B;
import com.taobao.txc.common.c.z;
import com.taobao.txc.common.config.o;
import com.taobao.txc.common.f;
import com.taobao.txc.common.j;
import com.taobao.txc.resourcemanager.i;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang.ClassUtils;

public class MtResourceManager
  extends i
{
  private static final LoggerWrap b = LoggerInit.logger;
  private static AtomicInteger c = new AtomicInteger(0);
  private final Map<String, b> d = new HashMap();
  private Map<String, Object> e = new HashMap();
  boolean a = false;
  private static ScheduledExecutorService f = Executors.newSingleThreadScheduledExecutor();
  private static int g = 3600;
  
  public MtResourceManager()
  {
    int i = c.getAndAdd(1);
    if (i != 0) {
      throw new RuntimeException("Define MtResourceManager repeatedlly!");
    }
  }
  
  public static MtResourceManager getTxcResourceManager()
  {
    return (MtResourceManager)i.a("mt");
  }
  
  private Integer d()
  {
    String str = g.f();
    return o.a().c(str);
  }
  
  public void c()
  {
    if (this.a) {
      return;
    }
    try
    {
      StringBuilder localStringBuilder = new StringBuilder();
      Object localObject1 = this.e.keySet().iterator();
      while (((Iterator)localObject1).hasNext())
      {
        String str = (String)((Iterator)localObject1).next();
        Object localObject2 = this.e.get(str);
        Class localClass = ClassUtils.getClass(str);
        for (Method localMethod1 : localClass.getMethods()) {
          if (localMethod1.isAnnotationPresent(MtBranch.class))
          {
            MtBranch localMtBranch = (MtBranch)localMethod1.getAnnotation(MtBranch.class);
            if (localStringBuilder.length() != 0) {
              localStringBuilder.append(",");
            }
            localStringBuilder.append(localMtBranch.name());
            if (this.d.containsKey(localMtBranch.name())) {
              throw new com.taobao.txc.common.b.c("mt branch name " + localMtBranch.name() + " conflicts.");
            }
            Method localMethod2 = localObject2.getClass().getMethod(localMtBranch.commitMethod(), new Class[] { String.class, Long.TYPE, String.class });
            Method localMethod3 = localObject2.getClass().getMethod(localMtBranch.rollbackMethod(), new Class[] { String.class, Long.TYPE, String.class });
            b localb = new b(null);
            localb.c = localMethod3;
            localb.b = localMethod2;
            localb.a = localObject2;
            this.d.put(localMtBranch.name(), localb);
          }
        }
      }
      localObject1 = (com.taobao.txc.resourcemanager.c)b();
      if (localObject1 == null) {
        localObject1 = c.b(new ThreadPoolExecutor(32, 200, 500L, TimeUnit.SECONDS, new LinkedBlockingQueue(20000), new ThreadPoolExecutor.CallerRunsPolicy()));
      }
      ((com.taobao.txc.resourcemanager.c)localObject1).e(localStringBuilder.toString());
      b.info("register servicekey[" + localStringBuilder.toString() + "] of mt to MtRmRpcClient");
      this.a = true;
      f.scheduleAtFixedRate(new a(this), 60L, g, TimeUnit.SECONDS);
    }
    catch (Exception localException)
    {
      throw new com.taobao.txc.common.b.c(localException);
    }
  }
  
  public boolean b(String paramString)
  {
    return this.d.containsKey(paramString);
  }
  
  public void a(String paramString1, long paramLong, String paramString2, String paramString3, byte paramByte, String paramString4)
  {
    ((b)this.d.get(paramString2)).a(paramString1, paramLong, paramString3);
  }
  
  public void a(String paramString1, long paramLong, String paramString2, String paramString3, byte paramByte)
  {
    a(paramString1, paramLong, paramString2, paramString3, paramByte, f.b.a());
  }
  
  public void a(String paramString1, long paramLong, String paramString2, String paramString3, byte paramByte, int paramInt)
  {
    ((b)this.d.get(paramString2)).b(paramString1, paramLong, paramString3);
  }
  
  public void a(Map<String, Object> paramMap)
  {
    this.e = paramMap;
  }
  
  public void reportUdata(String paramString1, long paramLong, String paramString2, String paramString3, boolean paramBoolean)
  {
    if (paramBoolean == true)
    {
      TxcContext.a(paramString3);
      return;
    }
    z localz = new z();
    localz.b(paramLong);
    localz.b(paramString2);
    localz.a(j.a(paramString1));
    localz.a(paramString3);
    try
    {
      b.info("send report udata message:" + localz);
      A localA = (A)b().a(j.b(paramString1), localz, 30000L);
      if (localA.a() != B.a.a()) {
        throw new com.taobao.txc.common.b.c(localA.a(), localA.b());
      }
    }
    catch (Throwable localThrowable)
    {
      throw new com.taobao.txc.common.b.c(localThrowable);
    }
  }
  
  public void a(String paramString1, long paramLong, String paramString2)
  {
    throw new com.taobao.txc.common.b.c("MtResourceManager unsupport queryReadLocks");
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.resourcemanager.mt.MtResourceManager
 * JD-Core Version:    0.7.0.1
 */